package com.gxuwz.prrs.service;

import com.gxuwz.prrs.bean.Page;
import com.gxuwz.prrs.service.impl.*;

import java.util.*;

/**
 * @author 张钧
 * @Description
 * @create 2023-05-24 上午 11:33
 */
public class ServiceHolder {
	private static final Map<Class<? extends BaseService<?, ? extends Page<?>>>, Object> BEAN_MAP = new HashMap<>();

	private static final ServiceHolder INSTANCE;

	static {
		INSTANCE = new ServiceHolder();
		INSTANCE.registerBean(AuthServiceImpl.class, new AuthServiceImpl());
		INSTANCE.registerBean(CheckRecordServiceImpl.class, new CheckRecordServiceImpl());
		INSTANCE.registerBean(NoticeServiceImpl.class, new NoticeServiceImpl());
		INSTANCE.registerBean(PianoRoomServiceImpl.class, new PianoRoomServiceImpl());
		INSTANCE.registerBean(UpdateServiceImpl.class, new UpdateServiceImpl());
		INSTANCE.registerBean(AppointmentRecordServiceImpl.class,new AppointmentRecordServiceImpl());
	}

	private ServiceHolder() {
	}

	public static ServiceHolder getInstance() {
		return INSTANCE;
	}

	private <T, P extends Page<T>> void registerBean(Class<? extends BaseService<T, P>> clazz, Object o) {
		BEAN_MAP.put(clazz, o);
	}

	public <T, P extends Page<T>, S extends BaseService<T, P>> S getBean(Class<S> clazz) {
		return clazz.cast(BEAN_MAP.get(clazz));
	}
}
